package net.zjitc.controller.admin;

import net.zjitc.mapper.AdminMapper;
import net.zjitc.pojo.Admin;
import net.zjitc.service.AdminService;
import net.zjitc.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/admin")
public class adminLogin {
    @Autowired
    AdminService adminService;

    @RequestMapping(value = "/index")
    public String index(){
        return "/admin/login1";
    }

    @RequestMapping(value = "/login")
    public String login(Admin admin, HttpSession session, Model model){
        Admin a = adminService.login(admin);
        if (a != null)
        {
            session.setAttribute("admin",a);
            return "/admin/frame";
        }
        model.addAttribute("news","账号或密码错误，请重新输入");
        return "/admin/login1";
    }

    @RequestMapping(value = "/logout")
    public String logout(HttpSession session){
        session.removeAttribute("admin");
        return "/admin/login1";
    }
}
